<?php
class ome_ctl_admin_o2o_order extends desktop_controller
{
    function _views()
    {
        $orderObj    = app::get('ome')->model('orders');
        
        //o2o门店物流公司
        $dlyCorpObj    = app::get('ome')->model('dly_corp');
        $corpList      = $dlyCorpObj->getList('corp_id', array('d_type'=>2));
        
        $logi_ids      = array();
        foreach ($corpList as $key => $val)
        {
            $logi_ids[]    = $val['corp_id'];
        }
        
        //filter
        $base_filter = array('logi_id'=>$logi_ids, 'disabled'=>'false', 'status'=>'active');
        $sub_menu    = array(
                            0 => array('label'=>app::get('base')->_('全部'),'filter'=>$base_filter, 'optional'=>false),
                            1 => array('label'=>app::get('base')->_('未发货'),'filter'=>array_merge($base_filter, array('process_status'=>array('splited'), 'ship_status'=>'0')), 'optional'=>false),
                            2 => array('label'=>app::get('base')->_('已发货'),'filter'=>array_merge($base_filter, array('ship_status' =>array('1','3','4'))), 'optional'=>false),
                            3 => array('label'=>app::get('base')->_('已拒绝'),'filter'=>array_merge($base_filter, array('process_status'=>array('unconfirmed','confirmed'), 'ship_status'=>'0')),'optional'=>false),
        );
        
        foreach ($sub_menu as $k => $v)
        {
            $sub_menu[$k]['filter'] = $v['filter'] ? $v['filter'] : null;
            $sub_menu[$k]['addon'] = $orderObj->count($v['filter']);
            $sub_menu[$k]['href'] = 'index.php?app=ome&ctl='. $_GET['ctl'] .'&act='. $_GET['act'] .'&flt='. $_GET['flt'] .'&view='. $k;
        }
        
        return $sub_menu;
    }
    
    function index() {
        $op_id    = kernel::single('desktop_user')->get_id();
        
        $this->title = '门店履约订单';
        $this->order_type = 'active';
        $base_filter      = array();
        
        $sub_menu    = $this->_views();
        foreach ($sub_menu as $key => $value)
        {
            if($_GET['view'] == $key)
            {
                $base_filter    = $value['filter'];
            }
        }
        
        $params = array(
                    'title' => $this->title,
                    'use_buildin_new_dialog' => false,
                    'use_buildin_set_tag'=>false,
                    'use_buildin_recycle'=>false,
                    'use_buildin_export'=>false,
                    'use_buildin_import'=>false,
                    'use_buildin_filter'=>true,
                    'use_view_tab'=>true,
                    'finder_aliasname' => 'order_view'.$op_id,
                    'finder_cols' => 'order_bn,shop_id,total_amount,column_print_status,process_status,is_cod,pay_status,ship_status,payment,shipping,logi_id,logi_no,createtime,paytime,mark_type',
                    'base_filter' => $base_filter,
        );
        $this->finder('ome_mdl_o2o_orders', $params);
    }

}